<template>
  <div class="container">
    <data-view
      @extra-button-click="extraButtonClick"
      :propIsTdesign="true"
      :propNoEditRow="true"
      :propDisabledActiveNext="true"
      :propAutoFetchData="false"
      ref="dataView"
      propViewKey="device_circulate_settings_part_share"
    />
  </div>
</template>

<script>
export default {
  help:'配件分享',
  data() {
    return {}
  },
  mounted() {
    this.loadDtl()
  },
  methods: {
    loadDtl() {
      let wrapper = this.$newWrapper()
      wrapper.eq("set_type",this.constCommon.deviceSetType.sharePart)
      this.$refs.dataView.setQueryWrapper(wrapper)
    },
    extraButtonClick(para) {
      let { key: buttonKey } = para.button
      if (buttonKey == 'choice') { // 添加配件
        this.utilSelect.stockMore(
          this._saveBatchItem,
          '',
          '',
          '',
          -1,
          this.constCommon.dictType.baseMatrTypePart,
          '',
          '',
          '',
          '',
          {
            busType: this.constCommon.deviceSetType.sharePart
          }
        )
      } else if (buttonKey == 'push') { // 推送外网
        this.utilMessage.confirm('是否推送所有配件分享信息到外网平台?', this._push)
      }
    },

    // 添加明细
    _saveBatchItem(stockList) {
      this.utilVue.loadShow(true)
      stockList.forEach(item => {
        item.setType = this.constCommon.deviceSetType.sharePart
        item.deviceName = item.matrName
        item.deviceSn = item.sn
        item.stockId = item.id
        item.id = null
      })
      this.$ajax.post('/device/circulate_settings/saveBatch', stockList).then((resp) => {
        this.utilVue.loadHide()
        if (resp.code == 0) {
          this.utilMessage.success(resp.msg)
          this.loadDtl()
        }
      })
    },

    // 添加明细
    _push() {
      this.utilVue.loadShow(true)
      this.$ajax.get('/device/circulate_settings/pushAll').then((resp) => {
        this.utilVue.loadHide()
        if (resp.code == 0) {
          this.utilMessage.success(resp.msg)
          this.loadDtl()
        }
      })
    }
  },
  computed: {
  }
}
</script>
